package com.fone.player.billing.bean;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;

import com.fone.player.util.L;

public class ChargeRecordListBean extends PYBaseBean{

	private ArrayList<ChargeRecordBean> records;
	private String currentPage;
	private String itemnum;
	private String nurl;
	
	public String getNurl() {
		return nurl;
	}
	public void setNurl(String nurl) {
		this.nurl = nurl;
	}
	public ArrayList<ChargeRecordBean> getRecords() {
		return records;
	}
	public void setRecords(ArrayList<ChargeRecordBean> records) {
		this.records = records;
	}
	public String getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}
	public String getItemnum() {
		return itemnum;
	}
	public void setItemnum(String itemnum) {
		this.itemnum = itemnum;
	}
	@Override
	public ChargeRecordListBean parseXml(InputStream ins) {
		ChargeRecordListBean  chargeRecordListBean= null;
		if (ins == null) {
			return chargeRecordListBean;
		}
		
		try {
			ChargeRecordBean reBean = null;
			XmlPullParser parser = Xml.newPullParser();
			parser.setInput(ins, "utf-8");
			int evtType = parser.getEventType();
			while (evtType != XmlPullParser.END_DOCUMENT) {
				String tag = parser.getName();
				switch (evtType) {
				case XmlPullParser.START_TAG:
					if ("rst".equalsIgnoreCase(tag)) {
						chargeRecordListBean = new ChargeRecordListBean();
						records = new ArrayList<ChargeRecordBean>();
						
					} else if (null != chargeRecordListBean) {
						if("pr".equalsIgnoreCase(tag)){
							reBean = new ChargeRecordBean();
							
						}else if("dt".equalsIgnoreCase(tag)){
							reBean.setTime(parser.nextText());
						}else if("mt".equalsIgnoreCase(tag)){
							reBean.setRmb(parser.nextText());
						}else if("nn".equalsIgnoreCase(tag)){
							reBean.setNn(parser.nextText());
						}else if("cpt".equalsIgnoreCase(tag)){
							reBean.setChannel(parser.nextText());
						}else if ("rp".equalsIgnoreCase(tag)) {
							L.i("rp:", parser.getAttributeValue(0)+"》"+parser.getAttributeValue(1)+
						">"+parser.getAttributeValue(2));
							chargeRecordListBean.setNurl(parser.getAttributeValue(2));
							chargeRecordListBean.setItemnum(parser.getAttributeValue(1));
							chargeRecordListBean.setCurrentPage(parser.getAttributeValue(0));
//							if("m".equalsIgnoreCase(parser.getAttributeName(1))){
//								chargeRecordListBean.setCurrentPage(parser.getAttributeValue(1));
//							}
//							if("p".equalsIgnoreCase(parser.getAttributeName(2))){
//								
//							}
//							if("nurl".equalsIgnoreCase(parser.getAttributeName(0))){
//								
//							}
						}
						
					}
					break;
				case XmlPullParser.END_TAG:
					if("pr".equalsIgnoreCase(tag)&&reBean!=null){
						records.add(reBean);
					}
					break;
				}
				evtType = parser.next();
			}
		} catch (Exception e) {
			e.printStackTrace();
			L.e(L.TAG, "充值记录解析出错", e.getMessage());
			chargeRecordListBean = null;
		}finally{
			try {
				ins.close();
			} catch (IOException e) {
				e.printStackTrace();
				L.e(L.TAG, "充值记录解析出错...", e.getMessage());
			}
		}
		
		if(null != records && records.size()>0 ){
			chargeRecordListBean.setRecords(records);
		}
		return chargeRecordListBean;
	}

}
